<template>
  <div id="jointInspectionmap"></div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import maptalks from "./jointmaptalks";
@Component
export default class extends Vue {
  mapviews: any = null;
  public click(val: any): void {
    // 点击触发事件
    this.$router.push({
      path: "/jointInspection/substationoverview",
      query: val.myData,
    });
  }
  private mounted(): void {
    this.mapviews = this.mapviews || new maptalks("jointInspectionmap");
    this.mapviews.addClickEvent(this.click);
    this.getAllData();
  }
  // 变电站数据
  mapData: any = [];
  // 获取变电站数据
  getBdzZb() {
    return (this as any).$services.getBdzZb();
  }
  // 总览首页-区域1-查询变电站坐标信息
  getBdzZbPic() {
    return (this as any).$services.getBdzZbPic();
  }
  // 获取所有地图相关数据
  getAllData() {
    Promise.all([this.getBdzZb(), this.getBdzZbPic()]).then((res) => {
      let [BdzZb, BdzZbPic] = res.map((v) => {
        return v.data;
      });
      let obj = {};
      BdzZbPic.forEach((v) => {
        obj[v.BDZID] = v;
      });
      let data = BdzZb.map((v) => {
        let item = obj[v.BDZID];
        let newData = Object.assign(v, item);
        return newData;
      });
      this.mapData = data;
      this.setBdzData();
    });
  }
  setBdzData() {
    // console.log(this.mapData);
    // 0：未执行；1：执行中；2：已执行
    // 0：未执行；1：执行中；2：已执行
    //     0: {code: "", name: "全部"}
    // 1: {code: "0", name: "未执行"}
    // 2: {code: "1", name: "执行中"}
    // 3: {code: "2", name: "已执行"}
    // 4: {code: "3", name: "执行失败"}
    // "wzx"未巡视
    // "zxz"巡视中
    // "yzx"已巡视
    // "zxsb"巡视失败
    let wxjData = [];
    let xjzData = [];
    let xjwcData = [];
    let xjsbData = [];
    this.mapData.forEach((item) => {
      if (item.XSZT === "zxz") {
        xjzData.push(item);
      }else if (item.XSZT === "yzx") {
        xjwcData.push(item);
      }else if (item.XSZT === "zxsb") {
        xjsbData.push(item);
      }else{
         wxjData.push(item);
      }
    });

    this.mapviews.addWxj(wxjData);
    this.mapviews.addXjz(xjzData);
    this.mapviews.addXjwc(xjwcData);
    this.mapviews.addXjsb(xjsbData);
  }
}
</script>

<style lang="scss" scoped>
#jointInspectionmap {
  width: 100%;
  height: 100%;
}
</style>

